<?php

// Hopefully enable all error reporting
error_reporting(E_ALL | E_STRICT);

// Load up that session / Create a new one
session_start();

// Sets the default timezone
date_default_timezone_set('Europe/Helsinki');

$action = isset($_GET['action']) ? $_GET['action'] : null;
if (strlen($action) < 1) {
	$action = null;
}

// Load user-class so we can check login status
require_once('classes/user.php');
$user =& new User;


if ($user->isLoggedIn() || $action == 'login') {
	require_once('inc.functions.php');
	require_once('classes/fetcher.php');
	require_once('classes/page_handler.php');
	require_once('classes/courses.php');

	$fetcher      =& new Fetcher;
	$page_handler =& new Page_Handler;
	$courses      =& new Courses;
}

if ($action == 'login') {
	if (!$user->isLoggedIn()) {
		$username = $_POST['username'];
		$password = $_POST['password'];
		$user->login($username, $password);
	}
}
else if ($action == 'logout') {
	if ($user->isLoggedIn()) {
		$user->logout();
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Vår Plan - Varför krångla till det? <?php if (isset($_SESSION['currentTitle'])) echo '['.$_SESSION['currentTitle'].']' ?></title>
	<link type="text/css" href="css/ui-lightness/jquery-ui-1.7.1.custom.css" rel="stylesheet" />
	<link type="text/css" href="css/var_plan/var_plan.css" rel="stylesheet" />
	<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>	
	<script type="text/javascript" src="js/jquery-ui-1.7.1.custom.min.js"></script>
	<script type="text/javascript" src="js/var_plan.js"></script>
	<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script> 
</head>
<body>
<?php
if (!$user->isLoggedIn()) {
	include('templates/login.php');
	include('templates/help.php');
} else {
	include('templates/menu.php');
?> 
	<div id="wrapper">
		<div id="site">
<?php
	require_once('backend.php');
?>
		</div>
	</div>
<?php
}
?>
<div id="bottom_bar"> Detta är här för att testa en "bottom-bar" som på Facebook... Notifications? Snabblänkar? osv.</div>
</body>
</html>
